#ifndef __ChatterBoxServer_H__
#define __ChatterBoxServer_H__

#include <QStringList>
#include <QTcpServer>
#include <QTcpSocket>
#include <QMap>
#include <QSet>
#include "quizmain.h"
#include "database.h"

class QuizMain;

class ChatterBoxServer : public QTcpServer
{
    Q_OBJECT

    public:
        ChatterBoxServer(QObject *parent=0);
        void sendText(QString text);
        void sendQuestion(int nr, QString question);
        void sendHint(QString hint, int count, bool fullanswer = false);
        Database* getUserSrv();
        void sendUserList();

    private slots:
        void readyRead();
        void disconnected();

    protected:
        void incomingConnection(int socketfd);

    private:
        bool userNotExist(QString name);
        bool real; // used to check dublicate names.
        QuizMain *quizSrv;
        Database *userSrv;
        QSet<QTcpSocket*> clients;
        QMap<QTcpSocket*,QString> users;
};

#endif
